<?php
namespace jy_weishop\page;
defined('BY_JYA') or exit('error');
/*
	页面返回
*/
class groups extends \plugin{
	public function getmain($return=array(),$onepluginname=''){
		global $_RQ;
		$return['params']=array();
		$return['groupset']=$return['shopset'];
		if($_RQ['pid']){
			$return['pid']=$return['oneid']=$_RQ['pid'];
		}else{
			$return['pid']=0;
		}
		$parentid=0;
		if($return['shopset']['level']){
			$return['islevel3']=true;
			$groupspram=array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','mid'=>0,'merchid'=>0,'parentid'=>0);
			$groupspram['onepluginname']=$onepluginname;
			$onegroups=pdo_getall('jy_weishop_goods_group',$groupspram,array(),'','paixu desc');
			foreach($onegroups as &$ov){
				$ov['image']=tomedia($ov['image']);
				$ov['childs']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$ov['id']),array(),'','paixu desc');
				if(!$return['oneid']){			
					$return['oneid']=$ov['id'];
				}
				foreach($ov['childs'] as &$v3){
					$v3['childs']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$v3['id']),array(),'','paixu desc');
				}
			}
			$parentid=$return['oneid'];
		}
		$return['onegroups']=$onegroups;
		$groupspram=array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$parentid);
		if(!$parentid){
			$groupspram['mid']=0;
			$groupspram['onepluginname']=$onepluginname;
		}else{
			$return['params']['pcate']=$parentid;
			$return['pid']=0;
		}
		$levelinfo=pdo_getcolumn('jy_weishop_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'level');//会员等级信息
		$groupspram['showlevels OR']='ifnull(showlevels,\'\')=\'\' or showlevels like \'%;'.trim($levelinfo).';%\'';//等级浏览权限
		$category=pdo_getall('jy_weishop_goods_group',$groupspram,array(),'','paixu desc');
		foreach($category as &$item){
			$item['childs']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$item['id']),array(),'','paixu desc');
			if(!$return['pid']){			
				$return['pid']=$item['id'];
				$return['childs']=$item['childs'];
				$return['nowkey']=0;
				$return['nowchilds']=$item['childs'];
				if(!$parentid){
					$return['params']['pcate']=$return['pid']?:$category[0]['id'];
					$return['params']['ccate']=$item['childs'][0]['id'];
				}else{
					$return['params']['pcate']=$parentid;
					$return['params']['ccate']=$category[0]['id'];
					$return['params']['scate']=$item['childs'][0]['id']?:0;
				}
				$return['nowchildid']=$item['childs'][0]['id'];
			}
		}
		$searchkeyword=$this->plugin_setting('search')['keyword'];
		$return['searchkeyword']=explode(';',$searchkeyword);
		$return['category']=$category;
		//推荐
		$groupspram['isrecommand']=1;
		$recommend=pdo_getall('jy_weishop_goods_group',$groupspram);
		$return['recommend']=$recommend;
		if(count($recommend) && !$return['shopset']['level']){
			$return['childs']=$recommend;
			$return['pid']=0;
		}
		$return['labels']=pdo_getall('jy_weishop_goods_label',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title','labelname'));
		foreach($return['labels'] as &$labv){
			$labv['list']=json_decode($labv['labelname'],true);
		}
		$return['sharedata']=array(
			'title'=>$return['setting']['share_title']?'分类'.$return['setting']['share_title']:'分类-在线商城',
			'desc'=>$return['setting']['share_desc']?$return['setting']['share_desc']:'在线商城，一个属于自己的个人商城！',
			'link'=>custom_url('jy_weishop/shop.groups//fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>ATTACHMENT_URL.$return['setting']['share_image']
		);
		return $return;
	}
}